<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class Integral extends \app\BaseModel
{
    protected $name = "massage_integral_list";
    public function dataAdd($data)
    {
        $data["create_time"] = time();
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page = 10)
    {
        $data = $this->where($dis)->order("id desc")->paginate($page)->toArray();
        return $data;
    }
    public function coachDataList($dis, $page = 10, $month = "")
    {
        if(!empty($month)) {
            $firstday = date("Y-m-01", $month);
            $lastday = date("Y-m-d H:i:s", strtotime($firstday . " +1 month") - 1);
            $data = $this->where($dis)->whereTime("create_time", "<=", $lastday)->order("create_time desc,id desc")->paginate($page)->toArray();
        } else {
            $data = $this->where($dis)->order("create_time desc,id desc")->paginate($page)->toArray();
        }
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function updateOne($id)
    {
        $user_id = $this->where(["id" => $id])->value("user_id");
        $res = $this->where(["user_id" => $user_id])->where("id", "<>", $id)->update(["status" => 0]);
        return $res;
    }
    public function integralAdd($order)
    {
        $integral_insert = ["uniacid" => $order["uniacid"], "coach_id" => $order["coach_id"], "order_id" => $order["id"], "integral" => round($order["pay_price"], 2), "balance" => 100, "status" => -1, "user_id" => $order["user_id"], "user_cash" => $order["pay_price"], "type" => 2];
        $integral_model = new Integral();
        $integral_model->dataAdd($integral_insert);
        return true;
    }
}

?>